<template>
        <Modal title="相关方选择" :transfer=false  v-model="relatedPartyForSelectModal"  :width=900 @on-cancel="modelClose">
        <Form ref="form2" :model="form2" :label-width="120">
            <Row>
                <Col span="12">
                    <FormItem label="相关方名称:">
                        <Input type="text" v-model="form1.contractorName"/>
                    </FormItem>
                </Col>
                
                <Col span="12">
                    <Button icon="md-search" type="error" style="margin-left: 8px" @click="query">查询</Button>
                    <Button @click="reset" style="margin-left: 8px">重置</Button>
                </Col>
            </Row>
        </Form>

         <Table ref='table' height="500" :loading="loading" size="small" class="table" no-data-text="没有查询到相关数据!"
                highlight-row stripe border :columns="columns1" width="100%" :data="dataTable">
            </Table>
        <Row style="margin-right:10px;">
            <Col span="24">
                <Page :total="pagedata.total" :page-size="pagedata.pageSize" 
                    style="float: right" @on-page-size-change="pageSizeChange" @on-change="pageChange" 
                     :page-size-opts="pageSizeArray"
                    show-total show-sizer show-elevator/>
            </Col>
        </Row>
            <div slot="footer">
                <Button class='ivu-btn-save' :disabled="users==[]" :loading="buttonLoading" @click="submit()">确定</Button>
                <Button class='ivu-btn-cancel' @click="modelClose">取消</Button>
            </div>
        </Modal>
</template>

<script>
    import {Api} from '../../../../api/index.js'
    var cascaderDom = () => import('@/components/cascader-dom.vue');
    import { sessionStorage, cookie } from '../../../../common/cacheUtils.js';
    
    export default {
        components: {cascaderDom},
        props: ['companyId','relatedPartyForSelectModal'],
        data() {
            return {
                loading: false,
                buttonLoading:false,
                dataTable:[],
                form1: {
                    staffName: '',
                    contractorName: '',
                    orgId: '',
                    orgName: ''
                },
                pageSizeArray: [10, 20, 50],
                pagedata: {
                    total: 0,
                    pageSize: 10,
                    currentPage: 1,
                },
                columns1: [
                    {
                        width: 60,
                        align: 'center',
                        fixed: 'left',
                        render: (h, params) => {
                            let id = params.row.accountId;
                            let flag = false;
                            if (this.currentChoose === id) {
                                flag = true
                            }
                            let self = this
                            return h('div', [
                                h('Radio', {
                                props: {
                                    value: flag
                                },
                                on: {
                                    'on-change': () => {
                                    self.currentChoose = id;
                                    }
                                }
                                })
                            ])
                        }
                    },
                    {minWidth: 150, title: '所属单位', align: 'center', key: 'companyName',},
                    {minWidth: 150, title: '相关方名称', align: 'center', key: 'contractorName',},
                    {minWidth: 150, title: '类别', align: 'center', key: 'categoryName',},
                    {minWidth: 150, title: '法定代表人', align: 'center', key: 'legalPerson',},
                    {minWidth: 150, title: '特种作业人员上岗证数量', align: 'center', key: 'workLicenseNumber',},
                    {minWidth: 150, title: '特种作业人员数量', align: 'center', key: 'workerNumber',},
                    {minWidth: 150, title: '相关方负责人', align: 'center', key: 'constructionDirector',},
                    {minWidth: 150, title: '相关方负责人电话', align: 'center', key: 'constructionDirectorPhone',},
                    {minWidth: 150, title: '相关方单位安全员', align: 'center', key: 'safetyOfficer',},
                    {minWidth: 150, title: '相关方单位安全员电话', align: 'center', key: 'safetyOfficerPhone',}
                ],
                users:[],
                currentChoose:"",
                form2:{}
            }
        },
        mounted: function() {
          
        },
        methods: {
            modelClose(){
                this.$emit('closeModel');
            },
            pageChange(pageNum) {
                this.pagedata.currentPage = pageNum;
                this.query();
            },
            pageSizeChange(pageSize) {
                this.pagedata.pageSize = pageSize;
                this.query();
            },
            //查
            query() {
                this.loading = true;
                let data = {
                    startPage: this.pagedata.currentPage,
                    size: this.pagedata.pageSize
                }
                if (this.companyId) {
                    this.form1.orgId = this.companyId
                }
                data = Object.assign(data, JSON.parse(JSON.stringify(this.form1)));
                let url = Api.interestedPartiesEvaluateBookList
                this.$http.get(url, {params: data}).then((res) => {
                    this.dataTable = res.data.data.data;
                    this.pagedata.total = res.data.data.totalSize;
                    this.loading = false;
                }).catch(e => {
                    this.$Message.error("数据获取失败")
                })
            },
            reset() {
                this.currentChoose = "";
                this.form2 = {
                    userName: ''
                };
                this.pagedata.currentPage = 1;
                this.pagedata.total = 0;
                this.query();
            },
            setOrgId(data) {
                this.form2.orgId = data[data.length - 1];
            },
            submit(){
                 this.dataTable.forEach(item=>{
                     if(item.accountId == this.currentChoose){
                        this.buttonLoading=true
                        this.$emit('getSelectData',item);
                        this.users.splice(0);
                        this.$Message.success('成功!');
                        this.buttonLoading=false
                        this.$emit('closeModel');
                     }
                 })
            },
        }
    }
</script>
